'use strict';
var d = Object.defineProperty;
var f = (o, i, s) =>
  i in o
    ? d(o, i, { enumerable: !0, configurable: !0, writable: !0, value: s })
    : (o[i] = s);
var c = (o, i, s) => (f(o, typeof i != 'symbol' ? i + '' : i, s), s);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const g = require('../doc/createNode.cjs'),
  l = require('./identity.cjs'),
  m = require('./Node.cjs');
function a(o, i, s) {
  let e = s;
  for (let t = i.length - 1; t >= 0; --t) {
    const n = i[t];
    if (typeof n == 'number' && Number.isInteger(n) && n >= 0) {
      const r = [];
      (r[n] = e), (e = r);
    } else e = new Map([[n, e]]);
  }
  return g.createNode(e, void 0, {
    aliasDuplicateObjects: !1,
    keepUndefined: !1,
    onAnchor: () => {
      throw new Error('This should not happen, please report a bug.');
    },
    schema: o,
    sourceObjects: new Map(),
  });
}
const h = o =>
  o == null || (typeof o == 'object' && !!o[Symbol.iterator]().next().done);
class u extends m.NodeBase {
  constructor(s, e) {
    super(s);
    c(this, 'schema');
    Object.defineProperty(this, 'schema', {
      value: e,
      configurable: !0,
      enumerable: !1,
      writable: !0,
    });
  }
  clone(s) {
    const e = Object.create(
      Object.getPrototypeOf(this),
      Object.getOwnPropertyDescriptors(this),
    );
    return (
      s && (e.schema = s),
      (e.items = e.items.map(t =>
        l.isNode(t) || l.isPair(t) ? t.clone(s) : t,
      )),
      this.range && (e.range = this.range.slice()),
      e
    );
  }
  addIn(s, e) {
    if (h(s)) this.add(e);
    else {
      const [t, ...n] = s,
        r = this.get(t, !0);
      if (l.isCollection(r)) r.addIn(n, e);
      else if (r === void 0 && this.schema) this.set(t, a(this.schema, n, e));
      else
        throw new Error(
          `Expected YAML collection at ${t}. Remaining path: ${n}`,
        );
    }
  }
  deleteIn(s) {
    const [e, ...t] = s;
    if (t.length === 0) return this.delete(e);
    const n = this.get(e, !0);
    if (l.isCollection(n)) return n.deleteIn(t);
    throw new Error(`Expected YAML collection at ${e}. Remaining path: ${t}`);
  }
  getIn(s, e) {
    const [t, ...n] = s,
      r = this.get(t, !0);
    return n.length === 0
      ? !e && l.isScalar(r)
        ? r.value
        : r
      : l.isCollection(r)
        ? r.getIn(n, e)
        : void 0;
  }
  hasAllNullValues(s) {
    return this.items.every(e => {
      if (!l.isPair(e)) return !1;
      const t = e.value;
      return (
        t == null ||
        (s &&
          l.isScalar(t) &&
          t.value == null &&
          !t.commentBefore &&
          !t.comment &&
          !t.tag)
      );
    });
  }
  hasIn(s) {
    const [e, ...t] = s;
    if (t.length === 0) return this.has(e);
    const n = this.get(e, !0);
    return l.isCollection(n) ? n.hasIn(t) : !1;
  }
  setIn(s, e) {
    const [t, ...n] = s;
    if (n.length === 0) this.set(t, e);
    else {
      const r = this.get(t, !0);
      if (l.isCollection(r)) r.setIn(n, e);
      else if (r === void 0 && this.schema) this.set(t, a(this.schema, n, e));
      else
        throw new Error(
          `Expected YAML collection at ${t}. Remaining path: ${n}`,
        );
    }
  }
}
c(u, 'maxFlowStringSingleLineLength', 60);
exports.Collection = u;
exports.collectionFromPath = a;
exports.isEmptyPath = h;
